package jee.boot.module.config;

import jee.boot.common.utils.StringUtils;
import jee.boot.entity.auth.Employee;
import jee.boot.entity.auth.User;
import jee.boot.module.authority.service.EmployeeService;
import jee.boot.oauth.config.handler.LoadUserOwnerData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 加载员工数据到user中,也可以用别的方式实现...
 */
@Configuration
public class LoadUserOwnerConfig {
    @Autowired
    private EmployeeService employeeService;
    @Bean
    public LoadUserOwnerData loadUserOwnerData(){
        return new LoadUserOwnerData() {
            @Override
            public void loadOwner(User user) {
                if(user!=null && StringUtils.isNotBlank(user.getOwnerId())){
                    Employee employee = employeeService.get(new Employee(user.getOwnerId()));
                    user.setOwner(employee);
                }
            }
        };
    }
}
